package com.bz.sunmipay.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * 数据库创建
 * <p>
 * Created by Administrator on 2019/12/9.
 */
public class DBHelper extends SQLiteOpenHelper {
    public static final String TABLE_NAME = "payment_detail";
    private static final String DB_NAME = "payment.db";
    private static final int VERSION = 2;

    public DBHelper(Context context) {
        super(context, DB_NAME, null, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        try {
            db.beginTransaction();
            db.execSQL(Column.CREATE_TABLE);
            db.setTransactionSuccessful();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            db.endTransaction();
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

    public static class Column {
        public static final String USER_ID = "user_id";
        public static final String PAYMENT_ID = "payment_id";
        public static final String USER_NAME = "user_name";
        public static final String PAYMENT_AMOUNT = "payment_amount";
        public static final String PAYMENT_DATE = "payment_date";
        public static final String PAYMENT_TYPE = "payment_type";
        public static final String PAYMENT_RESULT = "payment_result";

        public static final String CREATE_TABLE =
                "CREATE TABLE " + TABLE_NAME + " (" +
                        PAYMENT_ID + " TEXT PRIMARY KEY, " +
                        USER_ID + " TEXT, " +
                        USER_NAME + " TEXT, " +
                        PAYMENT_AMOUNT + " TEXT, " +
                        PAYMENT_DATE + " TEXT, " +
                        PAYMENT_RESULT + " TEXT, " +
                        PAYMENT_TYPE + " TEXT );";
    }
}
